package com.xoms.admin.persist.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.xoms.admin.model.ProPureBackBean;
import com.xoms.admin.model.ProPureBackInfoBean;
import com.xoms.admin.model.vo.AuditPureBackBean;
import com.xoms.admin.model.vo.BatchPureBackBean;
import com.xoms.admin.model.vo.ProPureBackVo;
import com.xoms.admin.persist.dao.ProPureBackDao;
import com.xoms.util.StringUtil;

@Repository
public class ProPureBackImpl extends BaseImpl implements ProPureBackDao {
	
	final String NAME_SPACE = NAME_SPACE_HEADER + ".ProPureBackMapper";

	@Override
	public int selectCount(String startTime, String endTime, String storeHouseId) {
		Map<String, Object> params = new HashMap<String, Object>();
		if (!StringUtil.isEmpty(startTime)) {
			params.put("startTime", startTime);
		}
		if (!StringUtil.isEmpty(endTime)) {
			params.put("endTime", endTime);
		}
		if (!StringUtil.isEmpty(storeHouseId)) {
			params.put("storeHouseId", storeHouseId);
		}
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectCount", params);

	}

	@Override
	public List<ProPureBackBean> selectList(int page, int pageSize, String startTime, String endTime,
			String storeHouseId) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("start", page * pageSize);
		params.put("length", pageSize);
		if (!StringUtil.isEmpty(startTime)) {
			params.put("startTime", startTime);
		}
		if (!StringUtil.isEmpty(endTime)) {
			params.put("endTime", endTime);
		}
		if (!StringUtil.isEmpty(storeHouseId)) {
			params.put("storeHouseId", storeHouseId);
		}
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectList", params);

	}

	@Override
	public int selectDetailCount(String bid, String key) {
		Map<String, Object> params = new HashMap<String, Object>();
		if (!StringUtil.isEmpty(bid)) {
			params.put("bid", bid);
		}
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectDetailCount", params);
	
	}

	@Override
	public List<ProPureBackInfoBean> selectDetailList(String bid, String key, int page, int pageSize, int paging) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("start", page * pageSize);
		params.put("length", pageSize);
		if (!StringUtil.isEmpty(bid)) {
			params.put("bid", bid);
		}
		params.put("paging", paging);
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectDetailList", params);

	}

	@Override
	public ProPureBackBean selectOneById(String bid) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectOneById", bid);
		
	}

	@Override
	public int delDetails(String bid) {
		return sqlSessionTemplate.delete(NAME_SPACE + ".delDetails", bid);
	}

	@Override
	public int updateSubmitStatus(String bid, int status) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("bid", bid);
		params.put("status", status);
		return sqlSessionTemplate.update(NAME_SPACE + ".updateSubmitStatus", params);
	}

	@Override
	public int del(String bid) {
		return sqlSessionTemplate.delete(NAME_SPACE + ".delete", bid);
	}

	@Override
	public String selectMaxNoInYear() {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectMaxNoInYear");
	}

	@Override
	public int insert(ProPureBackBean data) {
		return sqlSessionTemplate.insert(NAME_SPACE + ".insert", data);
	}

	@Override
	public int update(ProPureBackBean data) {
		return sqlSessionTemplate.update(NAME_SPACE + ".update", data);
	}

	@Override
	public int replaceBatchDetail(List<BatchPureBackBean> batch) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("list", batch);
		return sqlSessionTemplate.insert(NAME_SPACE + ".replaceBatchDetail", params);
	
	}

	@Override
	public AuditPureBackBean selectAuditPureBacksById(String aid) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectAuditPureBacksById", aid);
		
	}

	@Override
	public List<ProPureBackVo> selectProductListByPid(String pid) {
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectProductListByPid", pid);
	}

}
